package cate.game.server.configuration.part;

import cate.game.db.sqlite.GameSqlite;
import lombok.extern.slf4j.Slf4j;
import org.sqlite.SQLiteDataSource;

import java.io.File;

@Slf4j
public class GameSqliteImpl extends GameSqlite {

    private SQLiteDataSource ds = new SQLiteDataSource();

    @Override
    public GameSqlite setup(Object srvId) {
        String programFolder = null;
        try {
            programFolder = new File(".").getCanonicalPath();
        } catch (Exception e) {
            log.error("", e);
        }
        String dbFolder = programFolder + File.separator + "trace";
        String dbFileName = "game-"+srvId+".db";
        log.info("SQLite dbFolder={} dbFileName={}", dbFolder, dbFileName);
        new File(dbFolder).mkdirs();
        ds.setUrl("jdbc:sqlite:"+dbFolder+File.separator+dbFileName);
        initDao(ds);
        return this;
    }

}
